﻿using System.Collections.Generic;
using IQIGame.Onigao.GamePlay;
using LFloatMath.Math;

namespace IQIGame.Onigao.Logic
{
    public class BuffEffective_CustomState : BuffEffective
    {
        protected override void OnInitProperty(BuffEffectData rData, BuffComponent rTarget)
        {
            base.OnInitProperty(rData, rTarget);
            var rConfigData = new ConfigData();
            if (rData.param.Count > 0)
            {
                rConfigData.state = (EBuffCustomState)rData.param[0];
            }

            rData.userData = rConfigData;
        }

        protected override void OnActive(BuffEffectContext rContext, BuffEffectData rConfig, int nRuntimeParam)
        {
            base.OnActive(rContext, rConfig, nRuntimeParam);
            if (rConfig.userData is ConfigData rConfigData)
            {
                var rTarget = rContext.buff.target;
                rTarget.ModifyBuffState(rConfigData.state, true);
            }
        }

        protected override void OnDeActive(BuffEffectContext rContext, BuffEffectData rConfig)
        {
            base.OnDeActive(rContext, rConfig);
            if (rConfig.userData is ConfigData rConfigData)
            {
                var rTarget = rContext.buff.target;
                rTarget.ModifyBuffState(rConfigData.state, false);
            }
        }



        public class ConfigData : BuffEffectiveConfig
        {
            public EBuffCustomState state;
        }

#if UNITY_EDITOR
        public override string ToString(BuffEffectData rConfig)
        {
            return $"附加{((ConfigData)rConfig.userData).state}状态]";
        }
#endif
    }
}